<?php
// +----------------------------------------------------------------------
// | ThinkPHP [ WE CAN DO IT JUST THINK ]
// +----------------------------------------------------------------------
// | Copyright (c) 2006~2016 http://thinkphp.cn All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
// | Author: liu21st <liu21st@gmail.com>
// +----------------------------------------------------------------------

//return [
//    '__pattern__' => [
//        'name' => '\w+',
//    ],
//    '[hello]'     => [
//        ':id'   => ['index/hello', ['method' => 'get'], ['id' => '\d+']],
//        ':name' => ['index/hello', ['method' => 'post']],
//    ],
//
//];

use think\Route;

//获取用户token
Route::any('api/:version/token/user','api/:version.Token/getToken');

Route::get('api/:version/user/userinfo/[:id]','api/:version.User/getUserInfo');
//保存授权用户信息
Route::post('api/:version/user/save_userinfo','api/:version.User/setWechatUserInfo');
// 每点击抽奖一次，数据库抽奖次数减一
Route::get('api/:version/user/reduce_lottery_count','api/:version.User/reduceLotteryCount');





//Sample
Route::get('api/:version/sample/:key', 'api/:version.Sample/getSample');
Route::post('api/:version/sample/test3', 'api/:version.Sample/test3');

//Miss 404
//Miss 路由开启后，默认的普通模式也将无法访问
//Route::miss('api/v1.Miss/miss');

//Banner
Route::get('api/:version/banner/:id', 'api/:version.Banner/getBanner');

//Theme
// 如果要使用分组路由，建议使用闭包的方式，数组的方式不允许有同名的key
//Route::group('api/:version/theme',[
//    '' => ['api/:version.Theme/getThemes'],
//    ':t_id/product/:p_id' => ['api/:version.Theme/addThemeProduct'],
//    ':t_id/product/:p_id' => ['api/:version.Theme/addThemeProduct']
//]);

Route::group('api/:version/theme',function(){
    Route::get('', 'api/:version.Theme/getSimpleList');//?ids=1,2,3,...
    Route::get('/:id', 'api/:version.Theme/getComplexOne');
    Route::post(':t_id/product/:p_id', 'api/:version.Theme/addThemeProduct');
    Route::delete(':t_id/product/:p_id', 'api/:version.Theme/deleteThemeProduct');
});

//Route::get('api/:version/theme', 'api/:version.Theme/getThemes');
//Route::post('api/:version/theme/:t_id/product/:p_id', 'api/:version.Theme/addThemeProduct');
//Route::delete('api/:version/theme/:t_id/product/:p_id', 'api/:version.Theme/deleteThemeProduct');

//Product
//Route::post('api/:version/product', 'api/:version.Product/createOne');
//Route::delete('api/:version/product/:id', 'api/:version.Product/deleteOne');
//Route::get('api/:version/product/by_category/paginate', 'api/:version.Product/getByCategory');
//Route::get('api/:version/product/by_category', 'api/:version.Product/getAllInCategory');//?id=1...
//Route::get('api/:version/product/:id', 'api/:version.Product/getOne',[],['id'=>'\d+']);
//Route::get('api/:version/product/recent', 'api/:version.Product/getRecent');//?count=1...
Route::group('api/:version/product', function (){
    Route::post('', 'api/:version.Product/createOne');
    Route::delete('/:id', 'api/:version.Product/deleteOne');
    Route::get('/by_category/paginate', 'api/:version.Product/getByCategory');
    Route::get('/by_category', 'api/:version.Product/getAllInCategory');//?id=1...
    Route::get('/:id', 'api/:version.Product/getOne',[],['id'=>'\d+']);
    Route::get('/recent', 'api/:version.Product/getRecent');//?count=1...
    Route::get('/all_product', 'api/:version.Product/getAllProduct');
});

//Category
Route::get('api/:version/category', 'api/:version.Category/getCategories'); 
// 正则匹配区别id和all，注意d后面的+号，没有+号将只能匹配个位数
//Route::get('api/:version/category/:id', 'api/:version.Category/getCategory',[], ['id'=>'\d+']);
//Route::get('api/:version/category/:id/products', 'api/:version.Category/getCategory',[], ['id'=>'\d+']);
Route::get('api/:version/category/all', 'api/:version.Category/getAllCategories');

//Token
// Route::post('api/:version/token/user', 'api/:version.Token/getToken');

Route::post('api/:version/token/app', 'api/:version.Token/getAppToken');
Route::post('api/:version/token/verify', 'api/:version.Token/verifyToken');

//Address
Route::post('api/:version/address', 'api/:version.Address/createOrUpdateAddress');
Route::get('api/:version/address', 'api/:version.Address/getUserAddress');

//Order
Route::post('api/:version/order', 'api/:version.Order/placeOrder');
Route::get('api/:version/order/:id', 'api/:version.Order/getDetail',[], ['id'=>'\d+']);
// Route::put('api/:version/order/delivery', 'api/:version.Order/delivery');
Route::put('api/:version/order/delivery/:id', 'api/:version.Order/delivery',[], ['id'=>'\d+']);
Route::get('api/:version/order/delivery/:id', 'api/:version.Order/delivery',[], ['id'=>'\d+']);
Route::get('api/:version/order/confirm_goods/:id', 'api/:version.Order/confitmGoods',[], ['id'=>'\d+']);
Route::get('api/:version/order/check_logistics/:id', 'api/:version.Order/checkLogistics',[], ['id'=>'\d+']);
Route::put('api/:version/order/remind/:id', 'api/:version.Order/remind',[], ['id'=>'\d+']);
Route::get('api/:version/order/remind/:id', 'api/:version.Order/remind',[], ['id'=>'\d+']);
Route::post('api/:version/order/save_comments/:id', 'api/:version.Comments/saveComments',[], ['id'=>'\d+']);

//不想把所有查询都写在一起，所以增加by_user，很好的REST与RESTFul的区别
Route::get('api/:version/order/by_user', 'api/:version.Order/getSummaryByUser');//?page=1&size=3
Route::get('api/:version/order/paginate', 'api/:version.Order/getSummary');

//Pay
Route::post('api/:version/pay/pre_order', 'api/:version.Pay/getPreOrder');
Route::post('api/:version/pay/notify', 'api/:version.Pay/receiveNotify');
Route::post('api/:version/pay/re_notify', 'api/:version.Pay/redirectNotify');
Route::post('api/:version/pay/concurrency', 'api/:version.Pay/notifyConcurrency');

//Message
Route::post('api/:version/message/delivery', 'api/:version.Message/sendDeliveryMsg');

//Refund
Route::post('api/:version/refund/upload_img','api/:version.Refund/uploadImage');
Route::post('api/:version/refund/:id','api/:version.Refund/createRefund',[], ['id'=>'\d+']);
Route::get('api/:version/get_refund_info/:id','api/:version.Refund/getRefundInfo',[], ['id'=>'\d+']);
Route::put('api/:version/refund/refund/:id', 'api/:version.Refund/doRefund',[], ['id'=>'\d+']);
Route::get('api/:version/refund/refund/:id', 'api/:version.Refund/doRefund',[], ['id'=>'\d+']);

//活动active
Route::get('api/:version/active', 'api/:version.Active/getActiveList');
Route::post('api/:version/active/:id', 'api/:version.Active/getActiveByID',[], ['id'=>'\d+']);
Route::post('api/:version/active/save_luck_record', 'api/:version.LuckRecord/saveLuckRecord');
Route::get('api/:version/active/my_luck_records', 'api/:version.LuckRecord/getMyluckRecords');

Route::get('api/:version/luck_record/update_name', 'api/:version.LuckRecord/updateLuckRecordName');